package com.tourism.home.dao;

import com.tourism.home.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LikesDao {

    //帖子点赞数
    @Select("select count(uid) from tb_likes where pid=#{pid}")
    Integer getLikesByPID(@Param("pid") Integer pid);

    //得到帖子的点赞用户的id
    @Select("select uid from tb_likes where pid =#{pid}")
    List<Integer> getLikesPostUids(@Param("pid") Integer pid);

    //新增一条点赞记录
    @Insert("insert into tb_likes(pid, uid) values(#{pid}, #{uid})")
    Integer addLikes(@Param("pid") Integer pid, @Param("uid") Integer uid);

    //删除一条点赞记录
    @Delete("DELETE FROM tb_likes WHERE pid = #{pid} and uid=#{uid}")
    Integer deleteLikes(@Param("pid") Integer pid, @Param("uid") Integer uid);

    //删除一条点赞记录
    @Delete("DELETE FROM tb_likes WHERE pid = #{pid}")
    Integer deleteLikesByPID(@Param("pid") Integer pid);

    //用户点赞通知消息
    @Select("select tb_likes.id as id,send.id as sid,send.nickname as name1,rec.id as rid,rec.nickname as name2,tb_post.title as content,tb_post.id as link from tb_likes join tb_user as send on send.id = tb_likes.uid join tb_post on tb_likes.pid = tb_post.id join tb_user as rec on tb_post.uid = rec.id and rec.id=#{uid} and tb_likes.status = '未读'")
    List<Message> getMessageByUID(@Param("uid") Integer uid);

    @Update("update tb_likes set status = '已读' where id = #{id}")
    Integer updateLikesStatus(@Param("id") Integer id);
}
